//
//  MyAddTableViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "MyAddTableViewCell.h"
#import "TYAttributedLabel.h"
#import "MBButtonWithFontAdapter.h"
#import "MBLabelWithFontAdapter.h"
#import "MBTextFieldWithFontAdapter.h"
#import "MBTextViewWithFontAdapter.h"
#import "UIButton+WebCache.h"
@interface MyAddTableViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *head;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *userName;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *time;
@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *action;

@property (weak, nonatomic) IBOutlet UILabel *footView;
@property (weak, nonatomic) IBOutlet TYAttributedLabel *content;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footHeight;


@end

@implementation MyAddTableViewCell

- (void)awakeFromNib {

    self.selectionStyle = 0;
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.footView.backgroundColor = tabPlainBackColor;
    self.footHeight.constant = SCREEN_HEIGHT*0.03;
    
    self.headHeight.constant = SCREEN_WIDTH*0.07;
    self.headWidth.constant = self.headHeight.constant;
    radius(self.head, self.headHeight.constant/2);
    
    self.action.layer.borderColor = mainColor.CGColor;
    self.action.layer.borderWidth = 0.5;
}

-(void)setModel:(MyAddListModel *)model{
    
    _model = model;
    [self.head sd_setImageWithURL:[NSURL URLWithString:_model.avatar] forState:UIControlStateNormal];
    [self.userName setTitle:_model.author forState:UIControlStateNormal];
    self.time.text = _model.dateline;
    self.content.backgroundColor = [UIColor clearColor];
    
    self.content.text = _model.note;
    self.content.textColor = [UIColor lightGrayColor];
    self.content.font = [UIFont systemFontOfSize:15];
    
    self.action.selected = NO;

    
    [self.content sizeToFit];
    
    self.content.preferredMaxLayoutWidth = SCREEN_WIDTH-36;
    CGFloat Hhhh = [self.content getHeightWithWidth:SCREEN_WIDTH-36];
    
    self.contentHeight.constant = Hhhh;
    
    self.cellHight = Hhhh+SCREEN_HEIGHT*0.15;


}
- (IBAction)spaceAction:(UIButton *)sender {
    
    if ([self.deleget respondsToSelector:@selector(ToSpaceWhithUid:)]) {
        
        [self.deleget ToSpaceWhithUid:_model.from_id];
    }
}


- (IBAction)OkAction:(MBButtonWithFontAdapter *)sender {

    if (!sender.selected) {
        sender.selected = YES;
        
        [[Manager sharedManager]RequestWhithURL:GetFormhash AndParameter:nil AndCompletionType:^(id responseObject, DIEError *error) {
            
            if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {
                
                [self AgreeWhithFormhash:responseObject[@"data"][@"formhash"]];
            }
        }];
    }
}

-(void)AgreeWhithFormhash:(NSString *)formhash{
    
    NSLog(@"---%@",_model.from_id);
    

    NSDictionary *dic = @{@"formhash":formhash,@"uid":_model.from_id};
    [[Manager sharedManager]ResponseWhithURL:AgreeAdd AndParameter:dic AndCompletionType:^(id responseObject, DIEError *error) {
      
        
        NSLog(@"%@",responseObject);
        
//        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {
        
            if ([self.deleget respondsToSelector:@selector(agreeWhithCell:AndMessage:AndIsSucces:)]) {
                
                [self.deleget agreeWhithCell:self AndMessage:responseObject[@"message"] AndIsSucces:YES];
            }
            
//        }else{
//        
//            if ([self.deleget respondsToSelector:@selector(agreeWhithCell:AndMessage:AndIsSucces:)]) {
//                
//                [self.deleget agreeWhithCell:self AndMessage:responseObject[@"message"] AndIsSucces:YES];
//            }
//        }
    }];
}

@end
